package com.thinkgem.javamg.task;

import com.thinkgem.javamg.task.thread.PgatourThread;
import com.thinkgem.javamg.task.thread.SinaThread;
import com.thinkgem.javamg.task.thread.ToutiaoThread;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.PostConstruct;

/**
 * 应用启动初始化服务
 */
@Component
@Lazy(false)
@Transactional
@Scope("singleton")
public class InitDataService {
    static {
        //设置字符编码,异常乱码问题处理.
        System.setProperty("file.encoding", "UTF-8");
    }

    private static boolean init = false;

    @PostConstruct
    public void initData() {
        if (!init) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(1500);
                    } catch (InterruptedException e) {
                    }
                    //应用启动开启爬虫
                    new SinaThread().start();
                    new PgatourThread().start();
                    new ToutiaoThread().start();
                }
            }).start();
            init = true;
        }
    }
}